#ifndef _SGE_EDITOR_H_
#define _SGE_EDITOR_H_

#include <SGF.h>
#include <map>
#include <boost/function.hpp>

class IEditorTool;
class IEditorComponent;

class Editor:public irr::IEventReceiver
{
friend class IEditorComponent;
friend class IEditorTool;
public:
	Editor(Game* game,PluggableFactory* factory,MapManagerBase* mapManager,IEntity*(*getEntity)(Ogre::SceneNode*));
	~Editor();
	static Editor* getInstance(){return editor;}

	void start();
	void stop(){running=false;};

	bool OnEvent(const irr::SEvent& ev);

	fastsig::signal<void(const irr::SEvent::SKeyInput&)> keySignal;
	fastsig::signal<void(const irr::SEvent::SMouseInput&)> mouseSignal;
	fastsig::signal<void(const irr::SEvent::SJoystickEvent&)> joystickSignal;

	void selectEntity(SGF::IEntity* entity);
	SGF::IEntity* getSelectedEntity() const;
	void bindGUIEvent(irr::gui::IGUIElement* element,boost::function<void(const irr::SEvent&)> callback);
	
	Game* game;
	PluggableFactory* factory;
	MapManagerBase* mapManager;
	SGF::MapState* currentMap;	
	IEditorComponent *gui,*scene;

	fastsig::signal<void(SGF::IEntity*)> newEntitySelected;

protected:
	void onKey(const irr::SEvent::SKeyInput& ev);
	void onMouse(const irr::SEvent::SMouseInput& ev);
	
	static Editor* editor;
	IEntity* selectedEntity;
	std::map<irr::gui::IGUIElement*,boost::function<void(const irr::SEvent&)> > guiCallbacks;	
	(IEntity*)(*getEntity)(Ogre::SceneNode*);
	bool running;
	
};

#endif